package cn.openea.perpartner.meily.web.entity.dto;

import cn.openea.perpartner.meily.web.entity.ProvideSamples;
import cn.openea.perpartner.meily.web.service.IProvideSamplesSubService;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.function.Function;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 样品DTO
 * @createTime 2023年05月24日 02:54:00
 */
@Component
public class ProvideSamplesDTOFactory {

    @Resource
    private IProvideSamplesSubService samplesSubService;

    /**
     * 详情dto
     */
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @SuperBuilder
    public static class InfoAndIndicatorsDTO {
        /**
         * 样品详情
         */
        private ProvideSamples info;
        /**
         * 样品指标
         */
        private Map<String, Object> samplesIndicators;
    }

    public Function<ProvideSamples, InfoAndIndicatorsDTO> toInfoAndIndicatorsDTO = (provideSamples) -> {
        if (provideSamples == null) {
            return null;
        }
        InfoAndIndicatorsDTO infoAndIndicatorsDTO = new InfoAndIndicatorsDTO();
        infoAndIndicatorsDTO.setInfo(provideSamples);
        infoAndIndicatorsDTO.setSamplesIndicators(samplesSubService.indicatorQuery(provideSamples.getId()));
        return infoAndIndicatorsDTO;
    };


}
